---
title: "BM_PA_Figure2.Rmd"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Introduction

This file contains the needed code to reproduce Figure 2 in Brugarolas, P., and Miller, L. ‘The causal effect of polls on turnout intention: A local randomization regression discontinuity approach’.


```{r ck1}
library(rmarkdown)
library(haven)
library(rdrobust)
library(ggplot2)
```

```{r ck2}
data <- read_dta("../Data/BM_PA.dta")
```

```{r ck3}
## Figure 2: RD effect for the turnout intention (0.8 window)

p <- rdplot(data$ivotd, data$z, h=0.8, p=0, binselect = "qsmv", kernel = "uniform", x.lim = c( -2.6, 2.6), y.lim = c(0.5, 1.00), y.label= "Turnout intention", x.label= "Running variable: days to the publication of Poll 1", col.lines = "#6A1B2E",  col.dots="black")

plot <- p[["rdplot"]]

plot.formated <-plot +geom_vline(xintercept=c(-0.8,0.8), linetype="dotted") +
    theme(text=element_text(size=12),
          panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
        panel.background = element_rect(fill = "transparent",colour = NA),
        plot.background = element_rect(fill = "transparent",colour = NA),
          plot.title = element_blank(),
          legend.position = "bottom") 
plot.formated

 

ggsave(filename="../Results/Figures/Figure 2.pdf", plot=plot.formated, device="pdf",
       height=5, width=5, units="in", dpi=250, bg = "transparent")

```